Skip to content

Conversation

@joshheald
Copy link
Contributor

@joshheald joshheald commented Oct 28, 2022

Description

In #7915, we added a simpler YosemiteJustInTimeMessage model, more appropriate for UI and storage use than the nested Networking.JustInTimeMessageModel.

Initially, both were called JustInTimeMessage, and differentiated in code using their module names, where required... but unfortunately, this didn't work in the tests, because our generated code for .fake() and .copy() couldn't distinguish between the two models. This isn't normally a problem because Yosemite models are typically a type alias of the Networking model. For that reason, we had to include Yosemite in the type name, so that codegen would pick it up and have an unambiguous understanding of the types.

What this PR does

This PR changes our Codegen templates to use type.globalName rather than type.name when making the specs. (666249f)

That makes it big: +424/-424 lines of the changes are regenerating every .fake() and .copy() function, adding the module name to the extension of each model, and the return type of each fake and copy function it generates. (b9eef45)

Finally, it applies the benefits of the new module-aware generated code by renaming YosemiteJustInTimeMessage to JustInTimeMessage and specifying Yosemite. where necessary. (cf3cfe2)

What it doesn't do

We don't add modules to parameters of the .copy functions. I tried this by changing Models+Copiable.swifttemplate.fullyQualifiedName() to return type.globalName instead of type.name, however that ends up adding the module to parameters with all kinds of types, e.g. String. Networking.String doesn't really give us what we want!

I'm not really sure why this is, but it's not needed to fix the issue I was facing so it can be left for the future, in my opinion...

Testing instructions

The generated code is only used in tests, so to test, we check that the unit tests build and pass.


  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@joshheald joshheald added type: task An internally driven task. category: tooling Anything that involves building & maintaining the project, including scripts, `Fastfile`, etc. labels Oct 28, 2022
@joshheald joshheald added this to the 11.1 milestone Oct 28, 2022
@joshheald joshheald requested review from Ecarrion and koke October 28, 2022 12:06
@joshheald joshheald marked this pull request as ready for review October 28, 2022 12:06
@peril-woocommerce
Copy link

Warnings
⚠️ PR has more than 500 lines of code changing. Consider splitting into smaller PRs if possible.

Generated by 🚫 dangerJS

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Oct 28, 2022

You can test the changes from this Pull Request by:
  • Clicking here or scanning the QR code below to access App Center
  • Then installing the build number pr7970-d16587f on your iPhone

If you need access to App Center, please ask a maintainer to add you.

Copy link
Contributor

@Ecarrion Ecarrion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea @joshheald! Thanks for taking the time to improve our Codegen module! 🙇

# Conflicts:
#	Yosemite/Yosemite/Actions/JustInTimeMessageAction.swift
#	Yosemite/Yosemite/Stores/JustInTimeMessageStore.swift
@joshheald joshheald enabled auto-merge November 2, 2022 11:48
@joshheald joshheald disabled auto-merge November 2, 2022 11:48
@joshheald joshheald enabled auto-merge November 2, 2022 11:52
@joshheald joshheald merged commit 491104c into trunk Nov 2, 2022
@joshheald joshheald deleted the task/make-codegen-module-aware branch November 2, 2022 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: tooling Anything that involves building & maintaining the project, including scripts, `Fastfile`, etc. type: task An internally driven task.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants